<?php

namespace App\Console\Commands;

use App\Model\PayOrder;
use App\Model\UserProfile;
use Illuminate\Console\Command;

class Test extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'test:op {method} {param}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $method = $this->argument('method');
        $param = $this->argument('param');
        return $this->{$method}($param);
    }

    function modifyOrder($param)
    {
        $limit = $param;
        $where = [
            // ['finished_at', '<=', '2020-10-22']
        ];
        $orders = PayOrder::where($where)->orderBy('finished_at', 'desc')->limit($limit)->get();
        // dump($orders);
        $array = [2, 5, 10, 20, 50, 100];
        $channels = ['wechat', 'alipay'];
        foreach ($orders as $k => $order) {
            // for ($k = 0; $k < $limit; $k++) {
            $ts = time() + 3600 * 8 - $k * (mt_rand(500, 3600));
            $money = $array[array_rand($array)];
            $uid = UserProfile::pickRandUserId();
            $info = [
                // 'status' => PayOrder::STATUS_OK,
                // 'user_id' => $uid,
                'total_amount' => $money * 100,
                // 'send_coin' => 0,
                'recharge_coin' => $money,
                'finished_at' => date('Y-m-d H:i:s', $ts),
                // 'channel' => $channels[array_rand($channels)],
                // 'order_id' => PayOrder::genOrderId($uid)
            ];
            $ret = $order->update($info);
            // PayOrder::create($info);
            dump($k);
        }
    }
}
